﻿@{
    ViewData["Title"] = "移动单管理";
}
<div class="box2" panelTitle="检索条件">
    <form id="queryForm" method="post">
        <table formMode="transparent">
            <tr>
                <td>&nbsp;&nbsp;订单号：</td>
                <td><input type="text" name="orderNo" id="orderNo" /></td>
                <td>&nbsp;&nbsp;单据类型：</td>
                <td>
                    <select prompt="全部" url="/wms/MovementManage/getSelectMoveOrderType" name="orderType" id="orderType">
                    </select>
                </td>
                <td>&nbsp;&nbsp;单据状态：</td>
                <td>
                    <select prompt="全部" url="/wms/MovementManage/getSelectMoveOrderStatus" name="orderStatus" id="orderStatus">
                    </select>
                </td>
                <td>
                    &nbsp;&nbsp;创建时间：
                </td>
                <td>
                    <input type="text" class="date" name="startTime" style="width:auto" id="startTime" dateFmt="yyyy-MM-dd HH:mm:ss" />
                </td>
                <td>
                    &nbsp;&nbsp;至：
                </td>
                <td>
                    <input type="text" class="date" name="endTime" style="width:auto" id="endTime" dateFmt="yyyy-MM-dd HH:mm:ss" />
                </td>
                <td>&nbsp;&nbsp;是否启用：</td>
                <td>
                    <select name="enabled" id="enabled" selectedValue="Y" data='{"list":[{"value":"","key":"全部"},{"value":"Y","key":"是"},{"value":"N","key":"否"}]}'></select>
                </td>
                <td class="hiddenBL">&nbsp;&nbsp;补料类型：</td>
                <td class="hiddenBL">
                    <select prompt="请选择" url="/wms/MovementManage/getSelectFedbatchType" name="fedbatchType" id="fedbatchType">
                    </select>
                </td>
                <td><button type="button" onclick="searchHandler()"><span class="icon_find">查询</span></button></td>
                <td><button type="button" onclick="resetSearch()"><span class="icon_reload">重置</span></button></td>
            </tr>
        </table>
    </form>
</div>
<div class="padding_right">
    <div class="basicTab" id="myTab">
        <div name="移动单">
            <div id="maingrid"></div>
        </div>
        <div name="移动单明细">
            <div id="maingrid_detail"></div>
        </div>
        <div name="移动单条码">
            <div id="maingrid_barcode"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var grid; var grid_detail; var grid_barcode;
    function initComplete() {
        grid = $("#maingrid").quiGrid({
            columns: [
                { display: '单据号', name: 'orderNo', align: 'center', width: "12%" },
                { display: '关联单号', name: 'refOrderNo', align: 'center', width: "12%" },
                { display: '单据类型', name: 'orderTypeDesc', align: 'center', width: "12%" },
                { display: '补料类型', name: 'fedbatchTypeDesc', align: 'center', width: "12%" },
                { display: '单据状态', name: 'orderStatusDesc', align: 'center', width: "12%" },
                { display: '工厂代码', name: 'factoryCode', align: 'center', width: "12%" },
                { display: '备注', name: 'remarks', align: 'center', width: "12%" },
                { display: '创建时间', name: 'createTime', align: 'center', width: "12%" },
                {
                    display: '启用/禁用', name: 'enabled', align: 'center', width: "12%",
                    render: function (rowdata, rowindex, value, column) {
                        if (value == "Y") {
                            return "启用";
                        } else {
                            return "禁用";
                        }
                    }
                }
            ],
            url: '/wms/MovementManage/getMoveHeaderListByPage', sortName: 'ruid', rownumbers: true, checkbox: true,
            height: '100%', width: "100%", percentWidthMode: true, pageSize: 100,
            //顶部图标按钮栏
            toolbar: {}
        });

        grid_detail = $("#maingrid_detail").quiGrid({
            columns: [
                { display: '订单号', name: 'orderNo', align: 'center', width: "6%" },
                { display: '项目号', name: 'itemNo', align: 'center', width: "5%" },
                { display: '零件号简码', name: 'partSpec', align: 'center', width: "5%" },
                { display: '零件号', name: 'partNo', align: 'center', width: "8%" },
                { display: '数量', name: 'qty', align: 'center', width: "4%" },
                { display: '配料数量', name: 'pickQty', align: 'center', width: "4%" },
                { display: '出货数量', name: 'outQty', align: 'center', width: "4%" },
                { display: '接收数量', name: 'recQty', align: 'center', width: "4%" },
                { display: '单位', name: 'unit', align: 'center', width: "4%" },
                { display: '计划日期', name: 'planDate', align: 'center', width: "6%" },
                { display: '计划时间', name: 'planTime', align: 'center', width: "6%" },
                { display: '项目状态', name: 'itemStatusDesc', align: 'center', width: "5%" },
                { display: '源仓库代码', name: 'srcWarehouseName', align: 'center', width: "6%" },
                { display: '目标仓库代码', name: 'destWarehouseName', align: 'center', width: "6%" },
                { display: '源库区代码', name: 'srcZoneName', align: 'center', width: "6%" },
                { display: '源库存地', name: 'srcErpWarehouse', align: 'center', width: "6%" },
                { display: '目标库存地', name: 'destErpWarehouse', align: 'center', width: "6%" },
                { display: '工厂代码', name: 'factoryCode', align: 'center', width: "4%" },
                {
                    display: '启用/禁用', name: 'enabled', align: 'center', width: "4%",
                    render: function (rowdata, rowindex, value, column) {
                        if (value == "Y") {
                            return "启用";
                        } else {
                            return "禁用";
                        }
                    }
                },
            ],
            data: [], sortName: 'orderNo', rownumbers: true, checkbox: true,
            height: '100%', width: "100%", percentWidthMode: true, pageSize: 100
        });

        grid_barcode = $("#maingrid_barcode").quiGrid({
            columns: [
                { display: '领料单号', name: 'orderNo', align: 'center', width: "10%" },
                { display: '项目号', name: 'itemNo', align: 'center', width: "10%" },
                { display: '零件号', name: 'partNo', align: 'center', width: "10%" },
                { display: '零件号名称', name: 'partSpec', align: 'center', width: "10%" },
                { display: '条码', name: 'cartonNo', align: 'center', width: "10%" },
                { display: '数量', name: 'qty', align: 'center', width: "10%" },
                { display: '单位', name: 'unit', align: 'center', width: "10%" },
                { display: '状态', name: 'statusDesc', align: 'center', width: "10%" },
                { display: '工厂代码', name: 'factoryCode', align: 'center', width: "10%" },
                {
                    display: '启用/禁用', name: 'enabled', align: 'center', width: "10%",
                    render: function (rowdata, rowindex, value, column) {
                        if (value == "Y") {
                            return "启用";
                        } else {
                            return "禁用";
                        }
                    }
                },
            ],
            data: [], sortName: 'orderNo', rownumbers: true, checkbox: true,
            height: '100%', width: "100%", percentWidthMode: true, pageSize: 100
        });
        //载入工具栏图标
        loadToolbar("", grid);
        addDoubleClick("", grid);
        addDoubleClick("", grid_detail);

        $("#myTab").bind("actived", function (e, idx) {
            if (idx == 0) {
                grid.resetHeight();
                grid.resetWidth();
            }
            else if (idx == 1) {
                grid_detail.resetHeight();
                grid_detail.resetWidth();
            }
            else if (idx == 2) {
                grid_barcode.resetHeight();
                grid_barcode.resetWidth();
            }
        })
    }

    //查询
    function searchHandler() {
        //得到查询参数
        var query = $("#queryForm").formToArray();
        //将查询参数传给grid表格
        grid.setOptions({ params: query });
        //页号重置为1
        grid.setNewPage(1);
        //重新加载数据
        grid.loadData();
        $.post("/wms/MovementManage/getMoveDetailListByPage",
            {
                "orderNo": $("#orderNo").val()
            },
            function (result) {
                grid_detail.loadData(result);
            }, "json");
    }

    //重置查询
    function resetSearch() {
        $("#queryForm")[0].reset();
        searchHandler();
    }
    //双击
    function onDblClickRow(rowdata, rowid, rowobj) {

        var idxs = $("#myTab").attr("selectedIdx");
        if (idxs == 0) {
            $.post("/wms/MovementManage/getMoveDetailListByPage",
                {
                    "orderNo": rowdata.orderNo
                },
                function (result) {
                    grid_detail.loadData(result);
                }, "json");

            $("#myTab").basicTabSetIdx(1);
        }
        else if (idxs == 1) {
            $.post("/wms/MovementManage/getMoveSnListByPage",
                {
                    "orderNo": rowdata.orderNo,
                    "partNo": rowdata.partNo
                },
                function (result) {
                    grid_barcode.loadData(result);
                }, "json");

            $("#myTab").basicTabSetIdx(2);
        }
    }


    //添加
    function onAdd() {
        top.Dialog.open({ URL: "/wms/MovementManage/EditMovementManage", Title: "新增", Width: 750, Height: 500 });
    }


    //删除后的提示
    function handleResult(result) {
        if (result != -1) {
            top.Dialog.alert("删除成功！删除" + result + "条数据", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("删除失败！");
        }
    }

    //生成条码
    function onBarcodeGenerator() {
        var rows = grid.getSelectedRows();
        var rowsLength = rows.length;

        if (rowsLength == 0) {
            top.Dialog.alert("请选择零星入库单!");
            return;
        }

        if (rows[0].orderType != "20" && rows[0].orderType != "90") {
            top.Dialog.alert("该单据类型是" + rows[0].orderTypeDesc + "不允许生成");
            return;
        }
        if (rows[0].enabled != "Y") {
            top.Dialog.alert("该单据已禁用");
            return;
        }
        top.Dialog.confirm("是否确认生成条码？", function () {
            $.post("/wms/MovementManage/onBarcodeGenerator",
                //获取所有选中行
                getSelectOrderNo(grid),
                function (result) {
                    if (result.flag == "OK") {
                        top.Dialog.alert(result.message);
                        grid.loadData();
                    }
                    else {
                        top.Dialog.alert(result.message);
                    }
                },
                "json");
        });
    }


    //获取所有选中行获取选中行的id 格式为 ids=1&ids=2
    function getSelectId(grid) {
        var selectedRows = grid.getSelectedRows();
        var selectedRowsLength = selectedRows.length;
        var ids = "";

        for (var i = 0; i < selectedRowsLength; i++) {
            ids += selectedRows[i].ruid + ",";
        }
        return { "ids": ids };
    }

    function getSelectOrderNo(grid) {
        var selectedRows = grid.getSelectedRows();
        var selectedRowsLength = selectedRows.length;
        var ids = "";

        for (var i = 0; i < selectedRowsLength; i++) {
            ids += "'" + selectedRows[i].orderNo + "',";
        }
        return { "orderNos": ids };
    }

    //关闭
    function ClosehandleResult(result) {
        if (result == true) {
            top.Dialog.alert("单据关闭成功！", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("单据关闭失败！");
        }
    }

    //关闭
    function onClose() {
        $.post("/wms/MovementManage/onClose",
            //获取所有选中行
            getSelectOrderNo(grid),
            function (result) {
                ClosehandleResult(result.status);
            },
            "json");
    }

    //启用
    function EnablehandleResult(result) {
        if (result == true) {
            top.Dialog.alert("启用成功！", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("启用失败！");
        }
    }

    //禁用
    function DisablehandleResult(result) {
        if (result == true) {
            top.Dialog.alert("禁用成功！", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("禁用失败！");
        }
    }
    //启用
    function onEnable(rowid, rowidx) {
        var rows = grid.getSelectedRows();
        var rowsLength = rows.length;

        if (rowsLength == 0) {
            top.Dialog.alert("请选中要启用的记录!");
            return;
        }
        $.post("/wms/MovementManage/onEnable",
            //获取所有选中行
            getSelectOrderNo(grid),
            function (result) {
                EnablehandleResult(result.status);
            },
            "json");
    }
    //禁用
    function onDisable(rowid, rowidx) {
        var rows = grid.getSelectedRows();
        var rowsLength = rows.length;

        if (rowsLength == 0) {
            top.Dialog.alert("请选中要禁用的记录!");
            return;
        }
        top.Dialog.confirm("确定要禁用吗？", function () {
            $.post("/wms/MovementManage/onDisable",
                //获取所有选中行
                getSelectOrderNo(grid),
                function (result) {
                    DisablehandleResult(result.status);
                },
                "json");
        });
    }


    //刷新表格 表单提交的回调
    function afterFormSubmit() {
        grid.loadData();

        grid_detail.loadData();

    }

    //刷新表格数据并重置排序和页数
    function refresh(isUpdate) {
        if (!isUpdate) {
            //重置排序
            grid.options.sortName = 'orderNo';
            grid.options.sortOrder = "desc";
            //页号重置为1
            grid.setNewPage(1);

            grid_detail.options.sortName = 'orderNo';
            grid_detail.options.sortOrder = "desc";
            //页号重置为1
            grid_detail.setNewPage(1);

        }
        grid.loadData();
        grid_detail.loadData();
    }

</script>	